import edu.vanderbilt.isis.sm.Event;
import edu.vanderbilt.isis.sm.StateflowInterpreter;
import edu.vanderbilt.isis.sm.SymbolicDataProvider;

public class TestAnchorCell {
	// Anchor cell
	TopLevelAnchorCell ac;

	public TestAnchorCell() {
		this.ac = new TopLevelAnchorCell();

		this.ac.sim = new StateflowInterpreter(this.ac.sm, null); 
		//this.ac.sim.disablePrinting();

		this.ac.sim.initialize();		
	}

	/**
	 * Set initial bindings for AnchorCell.
	 * Arguments correspond to variables in the Organiser module of NuSMV model.
	 * Should be executed symbolically
	 */
	public void initAll(int mut_ac, int mut_lin15) {
		this.ac.r1.AnchorCell3.a_ac = mut_ac;
		this.ac.r1.AnchorCell3.a_lin15 = mut_lin15;
	}


	public void runMachines() {
		printAll("AC before executing any transition");

		// mut_ac = {ablated = 0, formed = 1}
		// mut_lin15 = {ko = 0, rf = 3, wt = 1}
		initAll(1, 3);
		// Initialize all
		
		Event e = new Event("");

		// pass empty event to all components and execute first step
		this.ac.sim.addEvent(e);  
		this.ac.sim.step();

		printAll("after first step");
		
		// iterate
		for (int i = 0; i < 30; i++) {
			System.out.println("i = " + i);

			this.ac.sim.addEvent(e);  
			this.ac.sim.step();

			printAll();
		}
	}

	public static void main(String[] args) {
		TestAnchorCell bs = new TestAnchorCell();
		bs.runMachines();		
	}
	
	// Printing methods

	public void printAll(){
		printAll("");
	}

	public void printAll(String msg){
		System.out.println("------------------ BioSystem");
		System.out.println("------------------ " + msg);
		
		printACState(this.ac);
	}

	/**
	 * Print current state of TopLevelAnchorCell instance
	 * @param ac
	 */
	private static void printACState(TopLevelAnchorCell ac) {
		StringBuilder builder = new StringBuilder();
		builder.append("AnchorCell={a_ac=" + ac.r1.AnchorCell3.a_ac);
		builder.append("; a_lin15=" + ac.r1.AnchorCell3.a_lin15);
		builder.append("; lin3=" + ac.r1.AnchorCell3.lin3);
		builder.append("; lin15=" + ac.r1.AnchorCell3.lin15);
		builder.append("; ISd0=" + ac.r1.AnchorCell3.ISd0);
		builder.append("; ISd1=" + ac.r1.AnchorCell3.ISd1);
		builder.append("; ISd2=" + ac.r1.AnchorCell3.ISd2);
		builder.append("; ISd3=" + ac.r1.AnchorCell3.ISd3);
		builder.append("}");
		System.out.println(builder.toString());
	}

}
